﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows;

using System.IO;
using System.Security.Cryptography;
using SplashScreenControl;
using System.Reflection;
using System.Threading;

namespace LinkUp
{
    public partial class GameMain : Form
    {
        #region 所有操作

        #region 游戏初始化
        public GameMain()
        {
            InitializeComponent();
            //开启双缓冲，防止绘图闪烁
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            //初始化排行榜
            InitRank();
            helpMsg = ShowHelp();
            ShowBackGraph();
        }
        #endregion

        #region 窗口重绘
        /// <summary>
        /// 窗口重绘
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (game != null)
            {
                Graphics g = e.Graphics;
                g.DrawImage(game.Screen.Map, new Point(game.Screen.GridStartPos.X, game.Screen.GridStartPos.Y));
            }
        }
        #endregion

        #region 处理鼠标点击
        /// <summary>
        /// 处理鼠标点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GameMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (game != null && game.State == GameState.Play)
            {
                int preClick = game.Click(e.X, e.Y);
                if (preClick > 0)
                {
                    pbBlock.Image = game.Screen.GetBigImage(preClick);
                    lbBlock.Text = game.Screen.GetBlock(preClick).BMsg;
                }
                else
                {
                    pbBlock.Image = null;
                    lbBlock.Text = string.Empty;
                    //消除游戏块
                    if (preClick == 0)
                    {
                        //画出路径
                        Bitmap map = new Bitmap(game.Screen.Map);
                        game.Screen.Map = game.ShowPath(game.Screen.Finder.PathPointList);
                        this.Refresh();
                        game.Screen.Map = map;
                        if (cpbTime.Value < cpbTime.Maximum - 2)
                        {
                            cpbTime.Value += 2;
                        }
                        else
                        {
                            cpbTime.Value = cpbTime.Maximum;
                        }
                        lbTime.Text = cpbTime.Value + "秒";
                        statusTime.Text = cpbTime.Value + "秒";
                        lbScore.Text = game.TotalScore + "分";
                        if (game.Remain == 0)
                        {
                            timer1.Stop();
                            this.Refresh();
                            //游戏通关
                            if (game.GLevel == GameLevel.Hard)
                            {
                                GameEnd(GameState.Win, false);
                                return;
                            }
                            else
                            {
                                DialogResult result = MessageBox.Show("恭喜过关\n\n奖励分数：" + (cpbTime.Value * 5).ToString() + "\n提示数：加1", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                if (result == DialogResult.OK)
                                {
                                    game.TotalScore += cpbTime.Value * 5;
                                    lbScore.Text = game.TotalScore + "分";

                                    game.NextLevel();
                                    //绘制背景
                                    ShowBackGraph();
                                    if (ckbbgSound.Checked)
                                        game.StartPlayBack();
                                    else
                                        game.StopPlayBack();
                                    cpbTime.Maximum = game.GTime;
                                    cpbTime.Value = game.GTime;
                                    this.btnPrompt.Enabled = true;
                                    this.timer1.Start();
                                }
                                else
                                {
                                    GameEnd(GameState.End, false);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (type == GameType.Pastime)
                            {
                                game.Screen.RefreshBlock();
                            }
                            this.Refresh();
                            game.RefreshBlock();
                        }
                    }
                }
                ShowPrompt();
                this.Refresh();
            }
        }
        #endregion

        #region 定时器处理
        /// <summary>
        /// 定时器处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (cpbTime.Value > 0)
            {
                if (cpbTime.Value < 6)
                {
                    game.Alarm();
                    lbTime.ForeColor = Color.Red;
                    statusTime.ForeColor = Color.Red;
                }
                else
                {
                    lbTime.ForeColor = Color.Black;
                    statusTime.ForeColor = Color.Black;
                }
                cpbTime.Value -= 1;
                lbTime.Text = cpbTime.Value + "秒";
                statusTime.Text = cpbTime.Value + "秒";
            }
            else
            {
                cpbTime.Value = cpbTime.Minimum;
                lbTime.Text = cpbTime.Value + "秒";
                statusTime.Text = cpbTime.Value + "秒";
                GameEnd(GameState.End, false);
            }
        }
        #endregion

        #region 游戏操作--按钮

        #region 开始游戏
        /// <summary>
        /// 创建新游戏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNew_Click(object sender, EventArgs e)
        {
            //初始化游戏
            try
            {
                if (game != null && (game.State == GameState.Play || game.State == GameState.Pause))
                {
                    DialogResult result = MessageBox.Show("游戏正在进行，您确定开始新游戏吗？", "游戏提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }

                //初始化游戏设置
                InitGame();
                game = new Game(this.IsFullScreen);
                //若死锁，则重排
                game.RefreshBlock();

                btnPrompt.Enabled = true;
                ShowPrompt();
                lbScore.Text = game.TotalScore + "分";
                cpbTime.Maximum = game.GTime;
                cpbTime.Value = game.GTime;
                List<Color> progressColors = new List<Color>();
                progressColors.Add(Color.Red);
                progressColors.Add(Color.DeepPink);
                progressColors.Add(Color.Orange);
                progressColors.Add(Color.LawnGreen);
                cpbTime.ColorList = progressColors;
                cpbTime.Location = new Point(this.statusStrip1.Location.X + (this.statusStrip1.Width - cpbTime.Width) / 2, this.statusStrip1.Location.Y + (this.statusStrip1.Height - cpbTime.Height) / 2);
                lbTime.Text = game.GTime.ToString() + "秒";
                this.statusTime.Text = game.GTime.ToString() + "秒";
                btnPause.Enabled = true;
                btnPause.Text = "暂停(F3)";
                pbBlock.Image = null;
                lbBlock.Text = string.Empty;
                game.IsPlaySound = cbMusic.Checked;
                if (ckbbgSound.Checked)
                    game.StartPlayBack();
                else
                    game.StopPlayBack();
                ShowBackGraph();
                menuSet.Enabled = false;
                this.timer1.Start();
                this.Refresh();
            }
            catch
            {
                MessageBox.Show("创建游戏失败，请检查配置文件！");
            }
        }
        #endregion

        #region 游戏提示
        /// <summary>
        /// 游戏提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrompt_Click(object sender, EventArgs e)
        {
            if (game != null && game.State == GameState.Play)
            {
                game.Prompt();
                if (game.PromptNum <= 0)
                {
                    btnPrompt.Enabled = false;
                }
                ShowPrompt();
                this.Refresh();
            }
        }
        #endregion

        #region 游戏暂停
        /// <summary>
        /// 游戏暂停
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPause_Click(object sender, EventArgs e)
        {
            if (game != null)
            {
                if (game.State == GameState.Play && btnPause.Text == "暂停(F3)")
                {
                    btnPause.Text = "继续(F3)";
                    menuStop.Text = "游戏继续";
                    game.State = GameState.Pause;
                    if (ckbbgSound.Checked)
                    {
                        game.StopPlayBack();
                    }
                    this.timer1.Stop();
                }
                else if (game.State == GameState.Pause)
                {
                    game.Pause -= 1;
                    btnPause.Text = "暂停(F3)";
                    menuStop.Text = "游戏暂停";
                    if (game.Pause <= 0)
                    {
                        btnPause.Enabled = false;
                    }
                    game.State = GameState.Play;
                    ShowPrompt();
                    if (ckbbgSound.Checked)
                    {
                        game.StartPlayBack();
                    }
                    this.timer1.Start();
                }
            }
        }
        #endregion

        #region 结束游戏
        /// <summary>
        /// 结束游戏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            if (game != null && (game.State == GameState.Play || game.State == GameState.Pause))
            {
                GameEnd(GameState.End, false);
            }
        }
        #endregion

        #endregion

        #region 设置游戏音乐
        /// <summary>
        /// 调整音效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbMusic_CheckedChanged(object sender, EventArgs e)
        {
            if (game != null)
            {
                game.IsPlaySound = cbMusic.Checked;
            }
        }
        /// <summary>
        /// 是否启动背景音乐
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ckbbgSound_CheckedChanged(object sender, EventArgs e)
        {
            if (game != null && game.State == GameState.Play)
            {
                if (ckbbgSound.Checked)
                {
                    game.StartPlayBack();
                }
                else
                {
                    game.StopPlayBack();
                }
            }
        }
        #endregion

        #region 游戏操作--菜单
        /// <summary>
        /// 游戏开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuStart_Click(object sender, EventArgs e)
        {
            btnNew_Click(sender, e);
        }
        /// <summary>
        /// 游戏提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void munePrompt_Click(object sender, EventArgs e)
        {
            btnPrompt_Click(sender, e);
        }
        /// <summary>
        /// 游戏暂停
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuStop_Click(object sender, EventArgs e)
        {
            btnPause_Click(sender, e);
        }
        /// <summary>
        /// 结束游戏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuEnd_Click(object sender, EventArgs e)
        {
            btnExit_Click(sender, e);
        }

        #region 本地排行榜
        /// <summary>
        /// 查看或上传本地排行榜
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UploadRank_Click(object sender, EventArgs e)
        {
            //打开本地排行榜
            RankForm rank = new RankForm();
            rank.Show();
        }
        #endregion

        #region 游戏设置

        /// <summary>
        /// 游戏设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuSet_Click(object sender, EventArgs e)
        {
            SetForm gameSet = new SetForm();
            gameSet.Show();
        }

        #endregion

        /// <summary>
        /// 游戏规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuHelp_Click(object sender, EventArgs e)
        {
            MessageBox.Show(helpMsg, "游戏提示");
        }
        /// <summary>
        /// 关于游戏 显示版权信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("连连看1.40版\n作者：彪哥\n时间：2009年2月\n中南大学软件与理论实验室\n感谢小唐、神保、彭总和峰哥的大力支持！", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        /// <summary>
        /// 游戏退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuExit_Click(object sender, EventArgs e)
        {
            btnExit_Click(sender, e);
            this.Close();
        }
        #endregion

        #region 私有变量
        private Game game = null;
        private string helpMsg = string.Empty;
        private List<User> sl = null;
        private GameType type = GameType.Standard;
        private Image backImage;
        private int recordCount;
        private DESCryptoServiceProvider key = new DESCryptoServiceProvider();
        private bool IsFullScreen
        {
            get { return this.WindowState == FormWindowState.Maximized; }
        }
        #endregion

        #region 私有方法
        /// <summary>
        /// 初始化排行榜
        /// </summary>
        private void InitRank()
        {
            try
            {
                XmlRW xml = new XmlRW(AppDomain.CurrentDomain.BaseDirectory + "\\app.config");
                recordCount = Convert.ToInt32(xml.GetValue("RecordCount"));
            }
            catch
            {
                MessageBox.Show("读取配置文件失败！\n", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            sl = new List<User>();
            string[] keyValue;
            User user;
            StreamReader sr;
            try
            {
                sr = new StreamReader("rank");
            }
            catch
            {
                //throw new Exception("无法加载排行信息，游戏初始化失败！");
                return;
            }
            try
            {
                while (!sr.EndOfStream)
                {
                    keyValue = Safe.Decrypt(sr.ReadLine(), key).Split('\t');
                    user = new User(keyValue[0], Convert.ToInt32(keyValue[1]));
                    if (keyValue.Length == 3)
                    {
                        user.IsUpload = bool.Parse(keyValue[2]);
                    }
                    sl.Add(user);
                }
            }
            catch
            {
                //本地排行榜数据格式有误
                MessageBox.Show("\n    友情提示\n\n新版本加密排行榜数据，\n更加安全可靠！\n\n旧版本本地排行数据将清空！\n网络排行榜数据仍保留！\n", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Dispose();
                }
            }
        }

        #region 初始化游戏设置
        /// <summary>
        /// 初始化游戏设置
        /// </summary>
        private void InitGame()
        {
            try
            {
                XmlRW xml = new XmlRW(AppDomain.CurrentDomain.BaseDirectory + "\\app.config");
                //设置游戏类型
                type = (GameType)(Convert.ToInt32(xml.GetValue("GameType")));
            }
            catch
            {
                MessageBox.Show("无法读取配置信息！", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        #endregion

        /// <summary>
        /// 游戏帮助
        /// </summary>
        private string ShowHelp()
        {
            StringBuilder msg = new StringBuilder("\t\t\t游戏规则\n\n");
            msg.Append("游戏概述：\n\t1.玩家可以将2个相同图案的对子连接起来，连接线\n\t  不多于3根直线，就可以成功将对子消除。\n");
            msg.Append("\t2.玩家有5次提示和3次暂停机会，每过一关，提示数加1。\n");
            msg.Append("关数设置：\n\t游戏一共5关，分别为简单、初级、标准、高级和专家。\n");
            msg.Append("时间设置：\n\t1.第一关：40秒，第三关：80秒，第五关：120秒。\n");
            msg.Append("\t2.每消除一对，游戏时间加2秒。\n");
            msg.Append("\t3.游戏时间为零时，游戏结束。\n");
            msg.Append("记分规则：\n\t1.每消除一对，得分加上当前积分倍数。\n");
            msg.Append("\t2.积分倍数随机区间与游戏难度有关，最大为(关数+5)倍积分。\n");
            msg.Append("\t3.若未消除或选中，积分倍数降为当前关数最低。\n");
            msg.Append("\t4.若游戏过关，奖励积分：剩余时间秒数×5。\n");
            msg.Append("排行规则：\n\t1.若游戏积分进入本地英雄榜，输入姓名，进入英雄榜。\n");
            msg.Append("\t2.玩家可以上传本地排行榜，查看游戏总排名。\n");
            msg.Append("\n\t祝您游戏愉快！");
            try
            {
                backImage = Image.FromFile("Images\\BackGround\\1.jpg");
            }
            catch
            {
                MessageBox.Show("无法加载图片，游戏初始化失败！");
            }
            return msg.ToString();
        }
        /// <summary>
        /// 绘制背景图片
        /// </summary>
        private void ShowBackGraph()
        {
            Bitmap m = null;
            Graphics g = null;
            if (game != null)
            {
                m = new Bitmap(game.Screen.BackGround.Width + game.Screen.BackOffset.X, game.Screen.BackGround.Height + game.Screen.BackOffset.Y);
                g = Graphics.FromImage(m);
                g.DrawImage(game.Screen.BackGround, game.Screen.BackOffset);
            }
            else if (this.WindowState != FormWindowState.Maximized)
            {
                m = new Bitmap(800, 664);
                g = Graphics.FromImage(m);
                g.DrawImage(new Bitmap(backImage, 800, 640), new Point(0, 24));
            }
            else
            {
                m = new Bitmap(SystemInformation.PrimaryMonitorSize.Width - 120, SystemInformation.PrimaryMonitorSize.Height - 20);
                g = Graphics.FromImage(m);
                g.DrawImage(new Bitmap(backImage, SystemInformation.PrimaryMonitorSize.Width - 120, SystemInformation.PrimaryMonitorSize.Height - 44), new Point(0, 24));
            }
            this.BackgroundImage = m;
            g.Dispose();
            this.Refresh();
        }
        /// <summary>
        /// 显示提示信息
        /// </summary>
        private void ShowPrompt()
        {
            lbLevel.Text = ((int)game.GLevel / 2 - 3).ToString() + "关";
            lbPrompt.Text = game.PromptNum.ToString() + "次";
            lbPause.Text = game.Pause.ToString() + "次";
            lbMulti.Text = game.Multiple.ToString() + "倍";
        }
        /// <summary>
        /// 加入排行榜
        /// </summary>
        /// <returns></returns>
        private void AddRank()
        {
            if (sl.Count < recordCount || game.TotalScore > sl[sl.Count - 1].Score)
            {
                //byte[] buffer = null;
                string id = InputBox.ShowInputBox();
                sl.Add(new User(id, game.TotalScore));
                sl.Sort();
                //删除排行榜最末一个
                if (sl.Count > recordCount) sl.RemoveAt(recordCount);
                StreamWriter sw = new StreamWriter("rank");
                for (int i = 0; i < sl.Count; i++)
                {
                    sw.WriteLine(Safe.Encrypt(sl[i].ID + "\t" + sl[i].Score.ToString() + "\t" + sl[i].IsUpload.ToString(), key));
                }
                sw.Dispose();
            }
        }
        /// <summary>
        /// 游戏结束处理
        /// </summary>
        /// <param name="state"></param>
        private void GameEnd(GameState state, bool isAuto)
        {
            if (game != null)
            {
                this.TopMost = false;
                menuSet.Enabled = true;
                menuRank.Enabled = true;
                game.State = state;
                this.timer1.Stop();
                ShowDefaultInfo();
                game.StopPlayBack();
                if (state == GameState.End)
                {
                    MessageBox.Show("游戏结束！您的游戏得分为：" + game.TotalScore.ToString() + "分。\n谢谢您的使用！", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (state == GameState.Win)
                {
                    MessageBox.Show("恭喜您，游戏通关，您真是太棒了！\n游戏总得分为：" + game.TotalScore.ToString() + "分。\n谢谢您的使用！", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (!isAuto)
                {
                    if (type != GameType.Pastime)
                    {
                        //加入排行
                        AddRank();
                    }
                    else if (sl.Count < recordCount || game.TotalScore > sl[sl.Count - 1].Score)
                    {
                        MessageBox.Show("\t对不起！\n您的游戏设置为娱乐型，\n得分不能计入统计排行！\n谢谢您的使用！\n", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            game = null;
            ShowBackGraph();
        }

        /// <summary>
        /// 还原游戏信息
        /// </summary>
        public void ShowDefaultInfo()
        {
            cpbTime.Value = 0;
            statusTime.Text = lbTime.Text = "秒";
            statusTime.ForeColor = lbTime.ForeColor = Color.Black;
            lbLevel.Text = "关";
            lbScore.Text = "分";
            lbPrompt.Text = "次";
            lbPause.Text = "次";
            lbMulti.Text = "倍";
        }
        #endregion

        #region 自动完成
        /// <summary>
        /// 处理自动完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuAutoPlay_Click(object sender, EventArgs e)
        {
            if (game != null && game.State == GameState.Play)
            {
                System.Threading.Thread autoPlay = null;
                try
                {
                    autoPlay = new System.Threading.Thread(new System.Threading.ThreadStart(AutoPlay));
                    autoPlay.Start();
                }
                catch
                {
                    autoPlay.Abort();
                    MessageBox.Show("自动消除出错！");
                }
            }
        }
        /// <summary>
        /// 自动消除，用于线程
        /// </summary>
        private void AutoPlay()
        {
            SetFormProperty(this, "Enabled", false);
            //this.Enabled = false;
            timer1.Stop();
            while (game.State != GameState.End)
            {
                game.AutoErase();
                //异步重绘窗体
                InvokeMethod(this, "Refresh", null);
            }
            game.StopPlayBack();
            MessageBox.Show("游戏结束！您的游戏得分为：" + game.TotalScore.ToString() + "分。\n谢谢您的使用！", "游戏提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            SetFormProperty(this, "Enabled", true);
        }

        #region 线程异步通信

        static AutoResetEvent reSet = new AutoResetEvent(false);

        delegate void SetFormPropertyHandler(Form f, string propertyName, object newValue);
        /// <summary>
        /// 异步设置窗体属性
        /// </summary>
        /// <param name="f"></param>
        /// <param name="propertyName"></param>
        /// <param name="newValue"></param>
        static void SetFormProperty(Form f, string propertyName, object newValue)
        {
            if (f.InvokeRequired)
            {
                Delegate d = new SetFormPropertyHandler(SetFormProperty);
                f.Invoke(d, new object[] { f, propertyName, newValue });
                reSet.WaitOne();
            }
            else
            {
                Type t = f.GetType();
                PropertyInfo pi = t.GetProperty(propertyName);
                pi.SetValue(f, newValue, null);
                reSet.Set();
            }
        }

        delegate void InvokeMethodHandler(Form f, string methodName, params object[] parms);
        /// <summary>
        /// 异步调用窗体方法
        /// </summary>
        /// <param name="f"></param>
        /// <param name="methodName"></param>
        /// <param name="parms"></param>
        static void InvokeMethod(Form f, string methodName, params object[] parms)
        {
            if (f.InvokeRequired)
            {
                Delegate d = new InvokeMethodHandler(InvokeMethod);
                f.Invoke(d, new object[] { f, methodName, parms });
                reSet.WaitOne();
            }
            else
            {
                Type t = f.GetType();
                MethodInfo mi = t.GetMethod(methodName);
                mi.Invoke(f, parms);
                reSet.Set();
            }
        }
        #endregion

        #endregion

        #region 处理全屏
        /// <summary>
        /// 处理全屏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainMenu_DoubleClick(object sender, EventArgs e)
        {
            if (this.WindowState != FormWindowState.Maximized)
            {
                this.FormBorderStyle = FormBorderStyle.None;
                this.WindowState = FormWindowState.Maximized;
                if (game != null)
                {
                    game.SetFullScreen();
                }
                ShowBackGraph();
                cpbTime.Width = this.statusStrip1.Width * 2 / 3;
                if (game != null)
                {
                    this.TopMost = true;
                    menuRank.Enabled = false;
                    menuSet.Enabled = false;
                }
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.WindowState = FormWindowState.Normal;
                if (game != null)
                {
                    game.SetNormal();
                }
                ShowBackGraph();
                cpbTime.Width = 600;
                this.TopMost = false;
                menuRank.Enabled = true;
                if (game == null)
                {
                    menuSet.Enabled = true;
                }
            }
            //设置进度条的位置
            cpbTime.Location = new Point(this.statusStrip1.Location.X + (this.statusStrip1.Width - cpbTime.Width) / 2, this.statusStrip1.Location.Y + (this.statusStrip1.Height - cpbTime.Height) / 2);
        }
        #endregion

        #region 显示闪屏
        /// <summary>
        /// 加载主窗体时显示闪屏
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SplashScreen.SetCommentaryString("...感谢小唐的大力支持.");
            System.Threading.Thread.Sleep(1200);

            SplashScreen.SetCommentaryString("...感谢神保、峰哥、彭总和华仔给予的帮助.");
            System.Threading.Thread.Sleep(800);

            SplashScreen.SetCommentaryString("...感谢所有关注彪哥连连看的朋友.");
            System.Threading.Thread.Sleep(800);
        }
        /// <summary>
        /// 显示主窗体时关闭闪屏
        /// </summary>
        /// <param name="e"></param>
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            //关闭闪屏
            SplashScreen.EndDisplay();
        }

        #endregion

        #endregion

    }
}